home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-30 | 9.9 KB | 387 lines | [TEXT/MMCC] |
- MacApp 3.1.1 mods for CW4.5
- Mark Anderson
- metrowerks
- 9/13/94
-
- •••Do not use these mods with versions of CW earlier than CW1.1.1.
- •••Scriptable Text Editor is necessary for the debug versions. STE is a part of
- AppleScript which is found on the CW4 CD.
-
- This file has the specific changes necessary for MacApp 3.1.1. If you would prefer
- to simplify the process, the folder "*OR* replace these files" has the complete
- files you need to change.
-
- In UMenuMgr.cp
-
- •••change IsSetupMenu to
-
- Boolean IsSetupMenu(MenuHandle aMenuHandle,
- Boolean isHierarchical)
-
- {
- if (!IsHandle((Handle) aMenuHandle))
- {
- #if qDebug
- VerboseIsHandle((Handle) aMenuHandle);
- ProgramBreak("In IsSetupMenu: not handed a handle.");
- #endif
- return false;
- }
-
- MenuID menuID = (*aMenuHandle)->menuID;
-
- if (menuID == mApple) return false; // _NEVER_ managed!
-
- #if qDebug
- if (menuID == mDebug) return true;
- #endif
-
- if (isHierarchical)
- {
- if ((menuID < kHierarchicalMin) || (menuID > kHierarchicalMax))
- return false; // must be in valid range for hierarchicals
- }
- return ((menuID >= mFirstMenu) && (menuID <= mLastMenu)); // Range of managed menus
-
- } // IsSetupMenu
-
- •••••••••••••••••••••
- In UMenuMgr.cp
-
- (In previous versions of my mods, I had you change EndMenuSetup. Please change
- it back to the original. The mod for IsSetupMenu makes this one unnecessary.)
- •••change EndMenuSetup to the original version which is
-
- void EndMenuSetup(MenuHandle aMenuHandle,
- Boolean isHierarchical,
- void* staticLink)
-
- {
- long newFlags;
-
- if (IsSetupMenu(aMenuHandle, isHierarchical))
- {
- newFlags = (*aMenuHandle)->enableFlags;
- // If any items are enabled, enable the menu
- if (newFlags != 0)
- {
- newFlags = (1 | newFlags);
- (*aMenuHandle)->enableFlags = newFlags;
- }
-
- // If the menu's enabled state changed, we have to draw the menu bar.
- if (((newFlags & 1) == 1) != ((SetupStructPtr)staticLink)->wasEnabled[(*aMenuHandle)->menuID])
- InvalidateMenuBar();
-
- // Restore the menuproc.
- (*aMenuHandle)->menuProc = ((SetupStructPtr)staticLink)->savedProcs[(*aMenuHandle)->menuID];
-
- // menuWidth set to 0 by routines that require CalcMenuSize, by
- // calling NeedCalcMenu.
- if (!(*aMenuHandle)->menuWidth)
- CalcMenuSize(aMenuHandle);
- }
- } // EndMenuSetup
-
- •••••••••••••••••••
- In UMacAppGlobals.cp
-
- •••Change original to
- void InitUMacApp_Step3(short callsToMoreMasters)
- {
- // Install MacApp's Memory management system
- InitUMemory(callsToMoreMasters);
-
- #if !qPowerPC
- UnloadAllSegments();
-
- // Force the init segment to be memory resident, so we can call UnloadAllSegs
- // during init
- short initSeg = GetSegNumber((ProcPtr) & DoInitUMacApp);
- #ifdef __MWERKS__
- //CW can't set up the jump table if if it has already been set up. If it's locked
- //then it's set up.
- {
- Handle seg;
- Handle GetSegResource(short segnum);
-
- seg = GetSegResource(initSeg);
- if (IsHandleLocked(seg)) // not yet locked
- (*gIsResidentSeg)[initSeg - 1] = true;
- else
- SetResidentSegment(initSeg, true);
-
- }
- #else
- SetResidentSegment(initSeg, true);
- #endif
- #endif
-
- DoInitUMacApp(); // do rest of initialization
-
- #if !qPowerPC
- SetResidentSegment(initSeg, false); // make it non-resident
- UnloadAllSegments();
- #endif
- } // InitUMacApp_Step3
-
- •••••••••••••••••••
- In UMacAppUtilities.h
-
- •••Change original to
-
- #if qDebug
- #ifdef __MWERKS__
- #pragma pointers_in_D0
- #endif
- Ptr GetCurStackFramePtr() = { 0x200E }; // MOVE.L A6,D0
- // Return the value of register A6.
- // Usually a pointer to the local
- // stack frame. Most often used to
- // find out the caller's name when
- // invoking a debugging routine.
-
- Ptr GetCurStackTop() = { 0x200F }; // MOVE.L A7,D0
- // Return the value of register A7.
- // Usually the top of the stack.
- // Useful for stack sniffing (not
- // a crime).
- #ifdef __MWERKS__
- #pragma pointers_in_A0
- #endif
- #endif
- •••••••••••••••••••
- In UMemory.cp
- In DoInitUMemory change original to
-
- SetResLoad(oldResLoad);
- //###########################################
-
- mainSegment = GetSegNumber((ProcPtr) & InitUMemory);// Main is always resident
- (*gIsResidentSeg)[mainSegment - 1] = true;
-
- utilitySegment = GetSegNumber((ProcPtr) & UnloadAllSegments);// Utilities are always resident
- (*gIsResidentSeg)[utilitySegment - 1] = true;
-
- #ifdef __MWERKS__ // __%Main must be resident
- (*gIsResidentSeg)[0] = true;
- #endif
-
- #if qModelFarCode
-
- •••••••••••••••••••
- In UMemory.cp
-
- •••Change original to
-
- short GetSegNumber(ProcPtr aProc)
- {
- static const short kLoaded = 0x4EF9; // if loaded then a JMP instruction
- #ifdef __MWERKS__
- static const short kUnLoaded = 0xA9F0; // if loaded then a JMP instruction
- const short offset = 6;
- #else
- static const short kUnLoaded = 0x3F3C; // if unloaded then a Move instruction (seg# onto stack)
- const short offset = 2;
- #endif
-
- if (*((const short *)aProc) == kLoaded) // loaded segment
- #ifdef __MWERKS__
- return *((const short *)((const char *) aProc + offset));
- #else
- return *((const short *)((const char *) aProc - offset));
- #endif
- else if (*((const short *)aProc) == kUnLoaded) // unloaded segment
- return *((const short *)((const char *) aProc + offset));
- else /* routine that computed &proc was in same
- segment as the proc */
- {
- #if qDebug
- ProgramBreak("GetSegNumber was not passed an jump table address");
- #endif
-
- return 0;
- }
- } // GetSegNumber
- •••••••••••••••••••
- In UMemory.cp
-
- •••Change original to
-
- void LoadResidentSegments()
- {
- short offset,
- segnum,
- rsrcCnt;
- Handle nameList, seg;
- SignedBytePtr p;
- CStr255 name;
- ResType theType;
- char savedState;
-
- rsrcCnt = CountResources('res!');
- for (short resIndex = 1; resIndex <= rsrcCnt; ++resIndex)
- {
- nameList = GetIndResource('res!', resIndex);
- savedState = HGetState(nameList);
- HNoPurge(nameList);
-
- offset = 2;
- short numNames = *((IntegerPtr) * nameList);
- for (short i = 1; i <= numNames; ++i)
- {
- p = (SignedBytePtr)(*nameList + offset);
- BlockMove(p, &name, *p + 1);
- offset += name.Length() + 1;
-
- seg = MAGet1NamedResource(kCode, name);
-
- if (seg)
- {
- GetResInfo(seg, &segnum, &theType, name);
- #ifdef __MWERKS__
- if (IsHandleLocked(seg)) // if its locked, then jump table is already set up
- (*gIsResidentSeg)[segnum - 1] = true;
- else
- #endif
- SetResidentSegment(segnum, true);
- }
- }
-
- HSetState(nameList, savedState);
- ReleaseResource(nameList);
- }
- } // LoadResidentSegments
-
- •••••••••••••••••••
- In UMemory.cp
-
- •••Just before DoUnloadAllSegments change original to
-
- typedef ModelFarCodeHeader *ModelFarCodeHeaderPtr,
- **ModelFarCodeHeaderHandle;
- #ifdef __MWERKS__
- const short kJTSkipOver = 4; //for large model, CW looks at the 2nd long in the resource
- #else
- const short kJTSkipOver = 2; // size of jmp (or loadseg) instruction
- // that must be skipped in the JT Entry in
- // order to get to the target address
- #endif
- #endif
-
- •••••••••••••••••••
- In UMemory.cp
-
- •••Change original to
-
- void DoUnloadAllSegments(void* scopeLink)
- {
- long* jmpTablePtr = (long*)scopeLink;
- short i;
- Handle seg;
- for (i = 0; i < pMaxSegNum; ++i)
- {
- if (!(*gIsResidentSeg)[i] && (*gIsLoadedSeg)[i])
- {
- seg = (*gCodeSegs)[i];
- if ((seg) && !IsHandlePurged(seg))
- {
- if (IsModelFarCodeSegment(seg))
- {
- if ((*((ModelFarCodeHeaderHandle)seg))->numOf16BitEntries)
- UnloadSeg((Ptr)(*jmpTablePtr + (*((ModelFarCodeHeaderHandle) seg))->
- A5OffsetOf16BitEntries + kJTSkipOver));
- else // Has to be the other since we wouldn't even
- // have a segment otherwise
- UnloadSeg((Ptr)(*jmpTablePtr + (*((ModelFarCodeHeaderHandle)seg))->
- A5OffsetOf32BitEntries + kJTSkipOver));
- }
- else
- {
- #ifdef __MWERKS__
- long firstProcInSegment = (*(long*)((*seg) + kJTSkipOver)) + (long) GetA5();
- UnloadSeg((Ptr)firstProcInSegment);
-
- #else
- UnloadSeg((Ptr)(*jmpTablePtr + **((IntegerHandle)seg) + kJTSkipOver));
- #endif
-
- }
- HNoPurge(seg);
- (*gIsLoadedSeg)[i] = false;
- }
- }
- }
- } // DoUnloadAllSegments
-
- •••••••••••••••••••
- In UObject.h
-
- •••Change original to
-
- //----------------------------------------------------------------------------------------
- // TObject: Definition of the system's root object
- //----------------------------------------------------------------------------------------
-
- DeclareClassDesc(TObject);
-
- // ••• JS NEW ••• singleobject + forceclassidfirst + classdescmany
-
- #if qMultipleInheritance || qPowerPC || defined(__MWERKS__) || defined(THINK_C) || defined(__SC__)
- #if (qDebug || qSym) && defined(__MWERKS__)
- // make sure CodeWarrior puts fClassID first, not the vtable
- struct ForceClassIDFirst
- {
- ClassID fClassID;
- };
- class TObject : public ForceClassIDFirst
- #else
- // assume the other compilers already put fClassID first (for Jasik)
- class TObject
- #endif
- #else
- // for MPW C only and no MI, descend from SingleObject, so vtables are smaller
- class TObject : public SingleObject
- #endif
- {
- DeclareClass(TObject);
-
- public:
-
- #if (qDebug || qSym) && !defined(__MWERKS__)
- ClassID fClassID; // Used to do object validation in debug mode.
- #endif
-
- •••••••••••••••••••
- In UApplication.cp
-
- •••Change the end of TApplication::DoMenuCommand to
-
- case cPerfMonEnd:
- {
- TerminatePerfMonitor();
- //MW I added this break; was there a reason it was missing?
- break;
- }
- #endif
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- } // TApplication::DoMenuCommand
-
- •••••••••••••••••••
- In ObjectHeap.cp
-
- •••I added the pragma segment because this entire file wasn't segmentized.
-
- //========================================================================================
- // CLASS ChunkyBlock
- //========================================================================================
- #pragma segment Main
-
- //----------------------------------------------------------------------------------------
- // ChunkyBlock::ChunkyBlock
- //----------------------------------------------------------------------------------------
-